<?php
$form = new Form($model);
$th = X3::db()->fetchAll("SELECT id, `mainheader`, title FROM data_theme");
$themes = array();
foreach ($th as $t){
    $themes[$t['id']] = array($t['title'],"/uploads/Theme/16x16/".$t['mainheader']);
}
unset($th);
if(!$model->getTable()->getIsNewRecord())
    $menu = Menu::get(array('page_id'=>$model->id),true);
else
    $menu = null;
?>
<h1><?=$model->getTable()->getIsNewRecord()?'Добавить материал':'Редактировать материал'?></h1>
<?if(!$model->getTable()->getIsNewRecord()):?>
<div class="admin-btns" style="padding:8px;border:1px solid #005999;background: rgba(128,128,220,0.4);">    
    <a class="button" href="/page:<?=$model->name?>.html">Посмотреть</a>     
    <a class="button" href="/page/delete/<?=$model->id?>">Удалить</a>
</div>
<?endif;?>
<div class="content">
    <?=  X3_Html::errorSummary($model)?>
<?/*    <iframe name="ifrm" id="ifrm"></iframe>
    <?=$form->start(array('action'=>'/page/doc','target'=>'ifrm'));?>
    <input name="file" type="file"  />
    <button type="submit">Go</button>
    <?=$form->end();?>*/?>
    <?=$form->start()?>
    <table width="100%">
        <?=$form->renderPartial(array('parent_id','theme_id','createmenu'))?>
        <tr>
            <td colspan="3" class="label"><label><?=$model->fieldName('title')?></label></td>
        </tr>
        <tr>
            <td colspan="3" class="field"><?=$form->input('title',array('style'=>'font:45px \'lombardina\', serif;width:100%'))?></td>
        </tr>
        <tr>
            <td colspan="3" class="label"><label><?=$model->fieldName('text')?></label></td>
        </tr>
        <tr>
            <td colspan="3" class="field"><?=$form->textarea('text')?></td>
        </tr>
        <tr>
            <td style="padding-top:15px" class="label"><label><?=$model->fieldName('music')?></label></td>
            <td class="field"><?=$form->hidden('music')?>
                <a class="add_music" href="#">Добавить</a>
            </td>
            <td style="padding-bottom: 15px;">&nbsp;</td>
        </tr>
        <?=$form->renderPartial(array('name','status'))?>
        <tr>
            <td colspan="3" class="field"><button type="submit">Сохранить</button></td>
        </tr>
    </table>
    <?=$form->end()?>
</div>
<script>
        var themes = <?=json_encode($themes)?>;
        var back_link = '<?=urlencode("page/add".($model->getTable()->getIsNewRecord()?'':"/id/$model->id"))?>';
</script>
<?=(!isset($_GET['x3_load_frame']))?X3::app()->cs->registerScriptFile('/js/page-add.js', X3_ClientScript::POS_END):'<script src="/js/page-add.js"></script>'; ?>